package com.imprenta.security;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.imprenta.bean.LoginBean;

public class AuteClienteFilter implements Filter {
	
	@SuppressWarnings("unused")
	private FilterConfig configuration;
	
	@Override
	public void init(FilterConfig filConfig) throws ServletException {
		// TODO Auto-generated method stub
		this.configuration = filConfig;
	}
	
	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		if (((HttpServletRequest)request).getSession().getAttribute(LoginBean.USER_KEY) == null){
			((HttpServletResponse)response).sendRedirect("../pages/login.xhtml");
		}else {
			chain.doFilter(request, response);
		}		
	}
	
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		configuration = null;
	}
}
